<!-- 卡片页 -->
<template>
  <view class="list-all">
    <view class="list-box" v-for="(item, index) in dataList" :key="index">
      <view v-if="showCheckBox" class="check-box">
        <uv-checkbox-group v-model="checkboxValue">
          <uv-checkbox :key="item.id" @change="onCheckboxChange(item.id)" :disabled="item.state !== 'DSY'"></uv-checkbox>
        </uv-checkbox-group>
      </view>
      <view class="main-list">
        <view class="img">
          <image class="image" :src="imageFile[0] ? imgMinioPath + imageFile[0]: '/static/image/pco/cs.png'" mode="aspectFill"></image>
            <template v-if="item.lookFlag === '0'">
                <view class="stateTag">
                    <image class="icon" src="/static/image/pco/warn.png"></image>
                </view>
                <view v-if="item.stateTag " class="stateTag2">
                    <view>{{ warningStateTagFormatter(item.stateTag) }}</view>
                </view>
            </template>
            <template v-else>
                <view v-if="item.stateTag" class="stateTag">{{ warningStateTagFormatter(item.stateTag) }}</view>
            </template>
        </view>
        <view class="content-box">
          <view class="title">
            <view>
              {{ item.orgName ? item.orgName : '--' }}
            </view>
          </view>
          <view class="content">
            <view class="line">
              <view class="img"><image src="/static/image/pco/monitor.png"></image></view>
              <view class="text">{{ item.warningArea ? item.warningArea : '--' }}</view>
            </view>
            <view class="line">
              <view class="img"><image src="/static/image/pco/message.png"></image></view>
              <view class="text">
                {{ item.warningDate ? dayjs(item.warningDate).format('YYYY-MM-DD HH:mm:ss') : '--' }}
              </view>
            </view>
            <view v-if="showState" class="line">
              <view class="img"><image src="/static/image/pco/state.png"></image></view>
              <view class="text" :class="getClasses(item.state)">{{ item.state ? warningStateFormatter(item.state) : '--' }}</view>
            </view>
          </view>
        </view>
        <view class="button-box">
          <slot name="button"></slot>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import { warningStateFormatter, warningStateTagFormatter} from "@/utils/formValidate";
  import dayjs from "dayjs";
  import config from '@/common/config';
  import {ref} from "vue";
  let imgMinioPath = ref(config.IMG_MINIO_PATH);
  let emits = defineEmits(['onCheckboxChange']);
  let props = defineProps({
    formData: {
      type: Array,
      default: () => []
    },
    imageFile: {
      type: Array,
      default: () => []
    },
    showCheckBox: {
      type: Boolean,
      default: false
    },
    showState: {
      type: Boolean,
      default: false
    }
  });

  let dataList = ref([]);
  let checkboxValue = ref([]);

  let init = () => {
      dataList.value = [
      {
        id: props.formData[0],
        orgName: props.formData[1],
        warningArea: props.formData[2],
        warningDate: props.formData[3],
        state: props.formData[4],
        lookFlag: props.formData[5],
        stateTag: props.formData[6],
        disable: false
      }
    ]
  };
  let getClasses = (state) => {
      return {
          'DZG': state === 'DZG',
          'DSY': state === 'DSY',
          'ZG_Z': state === 'ZG_Z',
          'YSY': state === 'YSY',
      }
  };
  init();

  /** 复选 */
  let onCheckboxChange = (e) => {
    emits('onCheckboxChange', e);
  };
</script>

<style scoped lang="scss">
  .list-all {
    background: #f6f6f6;
    padding: 0 0 20rpx 0;
  }

  .list-box {
    background: #ffffff;
    border-radius: 10rpx;
    display: flex;
    justify-content: space-between;
    height: 100%;
  }

  .check-box {
    width: 5%;
    padding-left: 20rpx ;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .main-list {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    padding: 15rpx 15rpx;
    border-radius: 10rpx;
  }

  .main-list .img {
    width: 180rpx;
    height: 100%;
    position: relative;
    display: inline-block;

    .image {
      display: block;
      width: 180rpx;
      height: 180rpx;
      border-radius: 10rpx;
    }

    .stateTag {
      top: 0;
      left: 0;
      color: #ffffff;
      width: 50rpx;
      font-size: 24rpx;
      position: absolute;
      padding: 5rpx 10rpx;
      text-align: center;
      border-radius: 10rpx 0 10rpx 0;
      background-color: rgba(245, 108, 108, 0.53);

      .icon {
        width: 30rpx;
        height: 30rpx;
      }
    }

    .stateTag2 {
      top: 0;
      left: 75rpx;
      color: #ffffff;
      width: 50rpx;
      font-size: 24rpx;
      position: absolute;
      padding: 5rpx 10rpx;
      text-align: center;
      border-radius: 10rpx 0 10rpx 0;
      background-color: rgba(245, 108, 108, 0.53);

      .icon {
        width: 30rpx;
        height: 30rpx;
      }
    }
  }

  .main-list .content-box {
    flex: 1;
    width: 60%;
    margin: 0 10rpx;

    .title {
      word-break: break-word;
      font-size: 30rpx;
      font-weight: bold;
    }

    .content {
      color: rgba(0, 0, 0, 0.6);
      font-size: 24rpx;

      .line {
        display: flex;
        justify-content: left;
        margin: 10rpx 0;

        .img {
          width: 10%;

          image {
            width: 30rpx;
            height: 30rpx;
            margin-right: 10rpx;
          }
        }

        .text {
          width: 90%;
          word-break: break-word;

          .dividingLine {
            width: 2rpx;
            margin: 0 10rpx;
            height: 30rpx;
          }
        }
      }
    }
  }

  .main-list .button-box {
    width: 0;
    align-items: flex-end;

    ::v-deep .uv-button-wrapper {
      top: 35rpx;
    }
  }

  .DZG{
      color: #EA0000;
  }
  .DSY{
      color: #EA8220;
  }
  .ZG_Z{
      color: #EA0000;
  }
  .YSY{
      color: rgba(0, 0, 0, 0.6);
  }
</style>